<template>
  <PageWrapper contentFullHeight>
    <CollapseContainer title="表单基础示例">
      <BasicForm @register="register" @submit="handleSubmit" @reset="handleReset" />
    </CollapseContainer>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicForm, FormSchema, useForm } from '@/components/Form';
  import { CollapseContainer } from '@/components/Container';
  import { PageWrapper } from '@/components/Page';

  import { useMessage } from '@/hooks/web/useMessage';

  const { createMessage } = useMessage();

  // prettier-ignore
  // 字段信息
  const schemas: FormSchema[] = [
    { 
      field: 'field1',
      component: 'InputCountDown',
      label: '基础',
      colProps: { span: 8 },
      componentProps:({ schema, formModel })=>{
        return {
          count:45,
          sendCodeApi:()=>{
            createMessage.info("发送验证码, 向手机号:" + formModel[schema.field]);
            return true;
          },
        }
      },
      rules:[
        {
          len:11,
        }
      ]
    },
   
  ];
  const [register] = useForm({
    labelWidth: 120,
    schemas,
    actionColOptions: { span: 24 },
    fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']],
  });

  const keyword = ref<string>('');

  // 重置方法
  function handleReset() {
    keyword.value = '';
  }

  // 提交方法
  function handleSubmit(values: any) {
    console.log('values', values);
    createMessage.success('click search,values:' + JSON.stringify(values));
  }
</script>
